package leetcode_week.leetcode_week2.question1;

import java.util.HashMap;
import java.util.Set;

class Solution {
    public int getLeastFrequentDigit(int n) {
        HashMap <Integer,Integer> map = new HashMap<>();
        while (n > 0) {
            int digit = n % 10;
            map.put(digit, map.getOrDefault(digit, 0) + 1);
            n = n / 10;
        }
        Set<Integer> keySet = map.keySet();
        int minCount = Integer.MAX_VALUE;
        int ans = -1;
        for (int i : keySet) {
           if (map.get(i) < minCount) {
               minCount = map.get(i);
               ans = i;
           }
        }
        return ans;
    }
}